<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
	#div1 {width: 100px; height: 100px; background: red; position: absolute;}
	
</style>
<script>
	
	
window.onload = function()
{
		var oDiv = document.getElementById('div1');
	
		var disX =0 ;
		var disY = 0;
	
		oDiv.onmousedown= function(ev)
		{
				//clientX clientY 鼠标坐标
				var oEvent = ev||event;
				disX = oEvent.clientX- oDiv.offsetLeft ;
				disY = oEvent.clientY -oDiv.offsetTop ;
				
			if (oDiv.setCapture)
				{
								//IE
								oDiv.onmousemove= mouseMove;
								oDiv.onmouseup = mouseup;

								oDiv.setCapture();
								
				}else
					{
							//  ff, chrome
							document.onmousemove= mouseMove;

							document.onmouseup = mouseup;
						return false;
					}
			
		};
	
	function mouseMove(ev)
	{
			var oEvent = ev||event;
			var left = oEvent.clientX - disX;
			var top = oEvent.clientY - disY;

			if(left<0)
			{
					left = 0;
			}

			if(top<0)
			{
					top = 0;
			}

			oDiv.style.left = left + 'px';
			oDiv.style.top = top + 'px';

	};
	
	function mouseup()
	{
				this.onmousemove =null;
				this.onmouseup=null;
			if(oDiv.setCapture)
				{
					oDiv.releaseCapture();
				}
	}
};
</script>
</head>

<body>
<div>dasaad</div>
<div>89jkjkj</div>
<div>llmmmm</div>
	<div id="div1">dsadsada</div>

</body>
</html>
